package com.zgtech.kernel.configserver.configserver.service.impl;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zgtech.kernel.configserver.configserver.model.dto.ConfigInfoDTO;
import com.zgtech.kernel.configserver.configserver.model.mapped.ConfigProperties;
import com.zgtech.kernel.configserver.configserver.service.IConfigService;
import org.apache.commons.lang.ArrayUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.pager.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/** 广告管理
 * @author WuGouQing
 * @version 1.0.0
 * @createTime 2019-03-14 17:29
 */
@Service
public class ConfigService implements IConfigService {

    @Autowired
    Dao dao;

    @Override
    public List<ConfigInfoDTO> getConfigList(String application, String profile, String label) {
        ConfigProperties configProperties = dao.fetch(ConfigProperties.class,
                Cnd.where("application", "=", application).
                        and("profile", "=", profile).
                        and("label", "=", label));
        if(configProperties==null){
            return Collections.emptyList();
        }
        Gson gson = new Gson();
        return gson.fromJson(configProperties.getKeyValueJson(), new TypeToken<List<ConfigInfoDTO>>() {}.getType());
    }
}
